package com.chengxiaoxiao.service.impl;

import com.chengxiaoxiao.commons.Page;
import com.chengxiaoxiao.dao.BlackListDao;
import com.chengxiaoxiao.dao.impl.BlackListDaoImpl;
import com.chengxiaoxiao.domain.BlackList;
import com.chengxiaoxiao.service.BlackListService;

import java.util.List;

public class BlackListServiceImpl implements BlackListService {
    private BlackListDao dao = new BlackListDaoImpl();

    @Override
    public void add(BlackList blackList) {
        dao.add(blackList);
    }

    @Override
    public void update(BlackList blackList) {
        dao.update(blackList);
    }

    @Override
    public void delete(long id) {
        dao.delete(id);
    }

    @Override
    public List get() {
        return dao.get();
    }

    @Override
    public BlackList getbyId(long id) {
        return dao.getbyId(id);
    }

    @Override
    public Page getListPage(String num) {
        int pageNum = 1;
        if (null != num && !"".equalsIgnoreCase(num)) {
            pageNum = Integer.parseInt(num);
        }

        int totalNumber = dao.getTotalNums();

        Page page = new Page(pageNum, totalNumber);
        List list = dao.getListPage(page.getStartIndex(), page.getPageSize());
        page.setRecords(list);

        return page;
    }

    @Override
    public Page getPageLikeSNum(String num,String snum) {
        int pageNum = 1;
        if (null != num && !"".equalsIgnoreCase(num)) {
            pageNum = Integer.parseInt(num);
        }

        int totalNumber = dao.getTotalNums();

        Page page = new Page(pageNum, totalNumber);
        List list = dao.getPageLikeSNum(page.getStartIndex(), page.getPageSize(),snum);
        page.setRecords(list);

        return page;
    }
}
